package com.lintf.batch.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @ author lintf
 * @ system Mac
 * @ data 2025/8/15
 * @ package_name com.lintf.batch.config
 * @ project_name my-diy-project
 * @ desc
 */
@Configuration
public class ExecutorConfig {

    /**
     * 创建批处理线程池执行器
     *
     * @return 线程池执行器
     */
    @Bean
    public TaskExecutor batchExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(8); // 增加核心线程数
        executor.setMaxPoolSize(16); // 增加最大线程数
        executor.setQueueCapacity(100); // 增加队列容量
        return executor;
    }

    /**
     * 创建手动分页多线程方案的线程池
     *
     * @return 线程池服务
     */
    @Bean
    public ExecutorService manualExecutor() {
        return Executors.newFixedThreadPool(8); // 使用固定线程池
    }

}
